//
//  MBSpaceMyCollectionShowViewController.m
//  MiBaoTu
//
//  Created by admin on 16/9/21.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceMyCollectionShowViewController.h"
#import "MBSpaceAddMusicViewController.h"
#import "MBSongDetailController.h"
#import "MBDetailViewController.h"
#import "MBSpaceAlbumViewController.h"
#import "MBSpacePeopelViewController.h"
#import "MBSongDetailForIController.h"
#import "AppDelegate.h"

#import "MBSpaceCollectionMusicCell.h"
#import "MBSpaceCollectionCompileView.h"
#import "SharePLayerView.h"
#import "MBSpaceMyAlbumCell.h"
#import "MBSpaceMyParentChildShowCollectionCell.h"
#import "MBSpaceZhuBoCell.h"

#import "MBDetailViewForIpadController.h"

#import "MBSongDetailForIpadController.h"
@interface MBSpaceMyCollectionShowViewController ()<UITableViewDataSource,UITableViewDelegate,MBSpaceCollectionCompileViewDelegate,MBSpaceCollectionMusicCellDelegate,SharePLayerViewDelegate,MBSpaceMyParentChildShowCollectionCellDelegate> {
    UITableView                             *_tableView;
    UILabel                                 *_showNoDataLb;
    MBSpaceCollectionCompileView            *_compileView;
    NSMutableArray                          *_selectMusicArr;//保存选中的歌曲
    CLShareManager *shareView;
    int                                     page;
    NSMutableArray                          *_mutAudioArr; //音频
    NSMutableArray                          *_mutAlbumArr; //专辑
    NSMutableArray                          *_mutAnchorArr; //主播
    NSDictionary                            *_selectCurrentMusicDic; //选中cell的dic
    MusicPLayType                           _musicPlayType;
    NSMutableArray                          *_fileIDArr;    //已下载的歌曲
    
    NSInteger                               parentSelectAniamtion; //亲子秀选中的行数--动画
    NSTimer                                 *_qzxTimer;
}

@property (nonatomic,assign)BOOL isCompiling;//是否批量编译
@property (nonatomic,assign)BOOL isAllSelcting;//是否全选

@end

@implementation MBSpaceMyCollectionShowViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self onUpdateUIForView:self.orientation];
    [self onLoadNew];
    
    if (_type == MyCollectionShowType_ParentChildShow) {
        if (!_isHideAllTableHeaderView) {
            [self onUpdateUIForTableAnimation];
        }
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if (_type == MyCollectionShowType_ParentChildShow) {
        if (!_isHideAllTableHeaderView) {
            if (_qzxTimer) {
                [_qzxTimer invalidate];
                _qzxTimer = nil;
            }
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isCompiling = NO;
    self.isAllSelcting = NO;
    _selectMusicArr = [[NSMutableArray alloc]init];
    page = 1;
    parentSelectAniamtion = 0;
    _mutAudioArr = [[NSMutableArray alloc]init];
    _mutAlbumArr = [[NSMutableArray alloc]init];
    _mutAnchorArr = [[NSMutableArray alloc]init];
    _selectCurrentMusicDic = [[NSDictionary alloc]init];
    _fileIDArr = [[NSMutableArray alloc]init];
    if (_isHideAllTableHeaderView) {
        _musicPlayType = MusicPLayType_SearchMusic;
    } else {
        _musicPlayType = MusicPLayType_Collection;
    }
    // Do any additional setup after loading the view.
    [self onCreateUI];
    
}

- (void)onCreateUI
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(ISIPAD?NAV_HEIGHT:(ISPortrait?NAV_HEIGHT:36))-80*PERCEN) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView = nil;
    [self.view addSubview:_tableView];
    [_tableView addLegendHeaderWithRefreshingTarget:self refreshingAction:@selector(onLoadNew)];
    [_tableView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(onLoadMore)];
    
    if (_isHideAllTableHeaderView == NO) {        
        if (self.type == MyCollectionShowType_Music) {
            _tableView.tableHeaderView = [self setTableHeaderViewWithIndex:3];
        }
        else if (self.type == MyCollectionShowType_Album) {
            _tableView.tableHeaderView = nil;
        }
        else if (self.type == MyCollectionShowType_ParentChildShow) {
            _tableView.tableHeaderView = [self setTableHeaderViewWithIndex:2];
        }
    }
    
    //暂无搜索结果
    _showNoDataLb = [[UILabel alloc]initWithFrame:CGRectMake(0, (_tableView.height-40)/2., _tableView.width, 40)];
    _showNoDataLb.backgroundColor = [UIColor clearColor];
    _showNoDataLb.text = @"暂无搜索结果";
    _showNoDataLb.textAlignment = NSTextAlignmentCenter;
    _showNoDataLb.textColor = UIColorFromHex(0x999999);
    _showNoDataLb.font = [UIFont systemFontOfSize:13.f];
    _showNoDataLb.hidden = YES;
    _showNoDataLb.userInteractionEnabled = YES;
    [self.view addSubview:_showNoDataLb];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTapSearchAction)];
    [_showNoDataLb addGestureRecognizer:tap];
    
    //批量弹出框
    _compileView = [[MBSpaceCollectionCompileView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 100*PERCEN)];
    _compileView.delegate = self;
    _compileView.orientation = self.orientation;
    _compileView.hidden = YES;
    [self.view addSubview:_compileView];
    
    shareView = [[CLShareManager alloc] init];
}

- (UIView *)setTableHeaderViewWithIndex:(NSInteger)index
{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*PERCEN)];
    bgView.backgroundColor = [UIColor clearColor];
    
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, bgView.width, 100*PERCEN)];
    contentView.backgroundColor = [UIColor whiteColor];
    [bgView addSubview:contentView];
    
    float itemWidth = 20*PERCEN;
    float btWidth = 1.*(bgView.width-(index+1)*itemWidth)/index;
    if (ISIPAD) {
        btWidth = (index==3?360*PERCEN:540*PERCEN);
    }
    for (int i=0; i<index; i++) {
        UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
        bt.frame = CGRectMake(itemWidth+(btWidth+itemWidth)*i, 18*PERCEN, btWidth, 64*PERCEN);
        if (ISIPAD) {
            bt.left = (self.orientation==UIDeviceOrientationPortrait?(contentView.width-btWidth*index-itemWidth*(index-1))/2.:440*PERCEN)+(btWidth+44*PERCEN)*i;
        }
        bt.backgroundColor = [UIColor whiteColor];
        [bt setTitleColor:UIColorFromHex(0x333333) forState:UIControlStateNormal];
        bt.layer.cornerRadius = 6.f;
        bt.layer.masksToBounds = YES;
        bt.layer.borderColor = UIColorFromHex(0x999999).CGColor;
        bt.layer.borderWidth = 1;
        bt.tag = 1000+i;
         bt.titleLabel.font = [UIFont systemFontOfSize:13.];
        [bt addTarget:self action:@selector(onTapForMusicAction:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:bt];
        
        if (i == 0) {
            [bt setTitle:@"播放全部" forState:UIControlStateNormal];
        }
        else if (i == 1) {
            [bt setTitle:@"批量操作" forState:UIControlStateNormal];
        }
        else if (i == 2) {
            [bt setTitle:@"更多" forState:UIControlStateNormal];
        }
    }
    
    return bgView;
}

- (void)onUpdateUIForTableAnimation
{
    //动态的改变动画
    //还没开始听歌
    AVPlayer *player = (AVPlayer *)[UserManager standerDefult].mainPlayer;
    if (!player) return;
    
    //不是亲子秀播放器
    NSArray *arr = (NSArray *)[UserManager standerDefult].qinzixiuArr;
    if (arr.count == 0) return;
    
    //计时器 判断播放的亲子秀是否未当前首
    _qzxTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onSHowTableAnimation) userInfo:nil repeats:YES];
}

- (void)onSHowTableAnimation
{
    if ([UserManager standerDefult].musicArr.count <= parentSelectAniamtion && parentSelectAniamtion < 0) return;
    
    NSUInteger selectIndex = [UserManager standerDefult].selectMusicIndex;
    
    MBSpaceMyParentChildShowCollectionCell *oldCell = (MBSpaceMyParentChildShowCollectionCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:parentSelectAniamtion inSection:0]];
    [oldCell onPlayerQinZinXiuMusicAnimation:NO];
    MBSpaceMyParentChildShowCollectionCell *newCell = (MBSpaceMyParentChildShowCollectionCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectIndex inSection:0]];
    [newCell onPlayerQinZinXiuMusicAnimation:YES];
    parentSelectAniamtion = selectIndex;
}

- (void)onLoadNew
{
    page = 1;
    [self loadData];
}

- (void)onLoadMore
{
    if (self.isCompiling == NO) {        
        ++page;
        [self loadData];
    } else {
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
    }
}

- (void)loadData
{
    NSArray *downedMusicArr = [UserManager standerDefult].downedMusicArr;
    [_fileIDArr removeAllObjects];
    NSMutableArray *arr1 = [[NSMutableArray alloc]init];
    NSMutableArray *arr2 = [[NSMutableArray alloc]init];
    for (int i=0; i<downedMusicArr.count; i++) {
        NSDictionary *dic = [downedMusicArr objectAtIndex:i];
        NSString *fileID = [dic objectForKey:@"fileID"];
        [arr1 addObject:fileID];
    }
    NSArray *downedQZXMusicArr = [[FMManageObject standerDefault]onSelectLocalParentChildShowCount];
    for (int i=0; i<downedQZXMusicArr.count; i++) {
        NSDictionary *dic = [downedQZXMusicArr objectAtIndex:i];
        NSString *fileID = [dic objectForKey:@"musicId"];
        if (![arr2 containsObject:fileID]) {
            [arr2 addObject:fileID];
        }
    }
    [_fileIDArr addObject:arr1];
    [_fileIDArr addObject:arr2];
    
    if (self.spaceType == MBSpaceMyCollectionShowType_Search || self.spaceType == MBSpaceMyCollectionShowType_Record) {
        [self loadSearchData];
        return;
    }
    
    if (_isHideAllTableHeaderView == YES) {
         if (self.type == MyCollectionShowType_Music) {
             _tableView.hidden = YES;
             _showNoDataLb.hidden = NO;
         } else {
             _tableView.hidden = NO;
             _showNoDataLb.hidden = YES;
         }
    }
    
    UserModel *userModel = [UserManager standerDefult].userModel;
    NSString *userid = [NSString stringWithFormat:@"%@",userModel.UserID];
    if (self.taUseId.length > 0) {
        userid = self.taUseId;
    }
    
    NSString *url = [NSString stringWithFormat:SPACE_COLLECTION_GET_AUDIOLIST_URL_PATH,userid,[NSString stringWithFormat:@"%d",page]];
    if (self.type == MyCollectionShowType_Music) {
        url = [NSString stringWithFormat:SPACE_COLLECTION_GET_AUDIOLIST_URL_PATH,userid,[NSString stringWithFormat:@"%d",page]];
    }
    else if (self.type == MyCollectionShowType_Album) {
        url = [NSString stringWithFormat:SPACE_COLLECTION_GET_ALBUMLIST_URL_PATH,userid,[NSString stringWithFormat:@"%d",page]];
    }
    else if (self.type == MyCollectionShowType_ParentChildShow) {
        url = [NSString stringWithFormat:SPACE_COLLECTION_GET_SHOWLIST_URL_PATH,userid,[NSString stringWithFormat:@"%d",page]];
    }
    
    [[HTTPManager standerDefault]AFGetRequest:url view:nil success:^(NSDictionary *json) {
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
        if ([json isKindOfClass:[NSDictionary class]]) {
            if ([json[@"ret_code"] integerValue]==0) {
                NSArray *arr = json[@"data"];
                if (arr.count > 0) {
                    if (self.type == MyCollectionShowType_Music) {
                        
                        if ([arr isKindOfClass:[NSArray class]]) {
                            if (page == 1) {
                                [_mutAudioArr removeAllObjects];
                            }
                            [_mutAudioArr addObjectsFromArray:arr];
                        }
                        if (_mutAudioArr.count == 0) {
                            _tableView.hidden = YES;
                            _showNoDataLb.hidden = NO;
                        } else {
                            _tableView.hidden = NO;
                            _showNoDataLb.hidden = YES;
                            
                            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
                            for (NSDictionary *dic in _mutAudioArr) {
                                if ([UserManager standerDefult].isLoadMusic && app.networkStatus == ReachableViaWiFi) {
                                    //开关打开而且在wife情况下
                                    [self onLoadMusic:dic];
                                }
                            }
                        }
                        
                        if (self.onBackChangeTitle) {
                            self.onBackChangeTitle(MyCollectionShowType_Music,_mutAudioArr.count);
                        }
                    }
                    else if (self.type == MyCollectionShowType_Album) {

                        if ([arr isKindOfClass:[NSArray class]]) {
                            if (page == 1) {
                                [_mutAlbumArr removeAllObjects];
                            }
                            [_mutAlbumArr addObjectsFromArray:arr];
                        }
                        if (_mutAlbumArr.count == 0) {
                            _tableView.hidden = YES;
                            _showNoDataLb.hidden = NO;
                        } else {
                            _tableView.hidden = NO;
                            _showNoDataLb.hidden = YES;
                        }
                        
                        if (self.onBackChangeTitle) {
                            self.onBackChangeTitle(MyCollectionShowType_Album,_mutAlbumArr.count);
                        }
                    }
                    else if (self.type == MyCollectionShowType_ParentChildShow) {

                        if ([arr isKindOfClass:[NSArray class]]) {
                            if (page == 1) {
                                [_mutAnchorArr removeAllObjects];
                            }
                            [_mutAnchorArr addObjectsFromArray:arr];
                        }
                        if (_mutAnchorArr.count == 0) {
                            _tableView.hidden = YES;
                            _showNoDataLb.hidden = NO;
                        } else {
                            _tableView.hidden = NO;
                            _showNoDataLb.hidden = YES;
                            
                            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
                            for (NSDictionary *dic in _mutAnchorArr) {
                                if ([UserManager standerDefult].isLoadMusic && app.networkStatus == ReachableViaWiFi) {
                                    //开关打开而且在wife情况下
                                    [self onLoadMusic:dic];
                                }
                            }
                        }
                        
                        if (self.onBackChangeTitle) {
                            self.onBackChangeTitle(MyCollectionShowType_Anchor,_mutAnchorArr.count);
                        }
                    }
                }
                [_tableView reloadData];

            }
        }
    } failure:^(NSError *error) {
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
    }];
}

- (void)loadSearchData
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString *url = [NSString stringWithFormat:STORY_SEARCHINFO_URL_PATH,self.searchText,[NSString stringWithFormat:@"%d",page],_fenlei,_fenling,_changjing];
    if (self.type != MyCollectionShowType_Music && self.type != MyCollectionShowType_Album) {
        url = [NSString stringWithFormat:STORY_SEARCHINFO_URL_PATH,self.searchText,[NSString stringWithFormat:@"%d",page],@"",@"",@""];
    }
    [[HTTPManager standerDefault]AFGetRequest:url view:nil success:^(NSDictionary *json) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
        if ([json isKindOfClass:[NSDictionary class]]) {
            NSDictionary *data = json[@"data"];
            if (self.type == MyCollectionShowType_Music) {
                //音频
                NSArray *arr = data[@"Audio"];
                
                if ([arr isKindOfClass:[NSArray class]]) {
                    if (page == 1) {
                        [_mutAudioArr removeAllObjects];
                    }
                    [_mutAudioArr addObjectsFromArray:arr];
                }
                if (_mutAudioArr.count == 0) {
                    _tableView.hidden = YES;
                    _showNoDataLb.hidden = NO;
                } else {
                    _tableView.hidden = NO;
                    _showNoDataLb.hidden = YES;
                }
                
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Music,_mutAudioArr.count);
                }
                 NSArray *arr1 = data[@"Album"];
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Album,arr1.count);
                }
                NSArray *arr2 = data[@"Anchor"];
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Anchor,arr2.count);
                }
            }
            else if (self.type == MyCollectionShowType_Album) {
                //专辑
                NSArray *arr = data[@"Album"];
                
                if ([arr isKindOfClass:[NSArray class]]) {
                    if (page == 1) {
                        [_mutAlbumArr removeAllObjects];
                    }
                    [_mutAlbumArr addObjectsFromArray:arr];
                }
                if (_mutAlbumArr.count == 0) {
                    _tableView.hidden = YES;
                    _showNoDataLb.hidden = NO;
                } else {
                    _tableView.hidden = NO;
                    _showNoDataLb.hidden = YES;
                }
                
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Album,_mutAlbumArr.count);
                }
            }
            else {
                //主播
                 if (_isHideAllTableHeaderView) {
                     
                     NSArray *arr = data[@"Anchor"];
                     
                     if ([arr isKindOfClass:[NSArray class]]) {
                         if (page == 1) {
                             [_mutAnchorArr removeAllObjects];
                         }
                         [_mutAnchorArr addObjectsFromArray:arr];
                     }
                     if (_mutAnchorArr.count == 0) {
                         _tableView.hidden = YES;
                         _showNoDataLb.hidden = NO;
                     } else {
                         _tableView.hidden = NO;
                         _showNoDataLb.hidden = YES;
                     }
                     
                     if (self.onBackChangeTitle) {
                         self.onBackChangeTitle(MyCollectionShowType_Anchor,_mutAnchorArr.count);
                     }
                 }
            }
            
       [_tableView reloadData];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
        _tableView.hidden = YES;
        _showNoDataLb.hidden = NO;
    }];
}

- (void)onTapSearchAction
{
    [self onLoadNew];
}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
     _tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(ISIPAD?NAV_HEIGHT:(ISPortrait?NAV_HEIGHT:36))-80*PERCEN);
    _showNoDataLb.frame = CGRectMake(0, (_tableView.height-40)/2., _tableView.width, 40);
    _compileView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 100*PERCEN);
    _compileView.orientation = self.orientation;
    if (_isHideAllTableHeaderView == NO) {
        if (self.type == MyCollectionShowType_Music) {
            _tableView.tableHeaderView = [self setTableHeaderViewWithIndex:3];
        }
        else if (self.type == MyCollectionShowType_Album) {
            _tableView.tableHeaderView = nil;
        }
        else if (self.type == MyCollectionShowType_ParentChildShow) {
            _tableView.tableHeaderView = [self setTableHeaderViewWithIndex:2];
        }
    }
    NSArray *arr = [[NSUserDefaults standardUserDefaults]objectForKey:@"SELECT_MUSIC_ALL"];
    if ([arr isKindOfClass:[NSArray class]]) {
        if (arr.count > 0) {
            //弹出批量框
            _tableView.height = SCREEN_HEIGHT-(ISIPAD?NAV_HEIGHT:(ISPortrait?NAV_HEIGHT:36))-80*PERCEN - 100*PERCEN;
            _compileView.top = _tableView.bottom;
            _compileView.hidden = NO;
        } else {
            //隐藏
            _tableView.height = SCREEN_HEIGHT-(ISIPAD?NAV_HEIGHT:(ISPortrait?NAV_HEIGHT:36))-80*PERCEN;
            _compileView.top = _tableView.bottom;
            _compileView.hidden = YES;
            self.isAllSelcting = NO; //不全选
            [_selectMusicArr removeAllObjects]; //删除所有选中的歌曲
        }
    }
    //返回按钮改变
    if (self.onChangeCompileStatus) {
        self.onChangeCompileStatus(self.isCompiling,self.type);
    }
    [_tableView reloadData];
}

#pragma mark - 分栏切换 更新UI
- (void)onUpdateUIForSelectScrollView
{
    //处于编辑模式，还原
    if (self.isCompiling) {
        UIButton *bt = (UIButton *)[self.view viewWithTag:1001];
        [self onTapForMusicAction:bt];
    }
    //返回按钮改变
    if (self.onChangeCompileStatus) {
        self.onChangeCompileStatus(NO,self.type);
    }
    [_tableView reloadData];
}

#pragma mark - 播放全部、批量、更多
- (void)onTapForMusicAction:(UIButton *)bt
{
    switch (bt.tag-1000) {
        case 0:
        {
            //播放全部
            if (_mutAudioArr.count > 0) {
                [[UserManager standerDefult]playMusicWithMusicArray:_mutAudioArr withCurrentIndex:0 withMusicPlayType:_musicPlayType];
            }
            else if (_mutAnchorArr.count > 0) {
                UserManager *manager = [UserManager standerDefult];
                
                NSString *idStr ;
                if (manager.audioPlayerType != AudioPLayerType_Qinzix) {
                    //初次进入
                    idStr = @"";
                    manager.audioPlayerType = AudioPLayerType_Qinzix;
                } else {
                    //2次进入
                    NSInteger selectIndex = manager.selectMusicIndex;
                    NSArray *arr = manager.musicArr;
                    Music *dics = [arr objectAtIndex:selectIndex];
                    idStr = [NSString stringWithFormat:@"%@",dics.ID];
                }
                [manager setSelectMusicIndex:0];
                [manager.musicArr removeAllObjects];
                [manager.musicArr addObjectsFromArray:[manager onTurnArrayFormQingZiXiuArray:_mutAnchorArr]];
                manager.selectMusicIndex = 0;
                [manager.qinzixiuArr removeAllObjects];
                [manager.qinzixiuArr addObjectsFromArray:_mutAnchorArr];
                
                MBDetailViewController *childShowVC = [[MBDetailViewController alloc] init];
                [childShowVC.dataAllArr addObjectsFromArray:_mutAnchorArr];
                childShowVC.selectMusicID = idStr;
                [self.navigationController pushViewController:childShowVC animated:YES];
            }
        }
            break;
        case 1:
        {
            //批量
            self.isCompiling = !self.isCompiling;
            if (self.isCompiling) {
                //弹出批量框
                _tableView.height = SCREEN_HEIGHT-(ISIPAD?NAV_HEIGHT:(ISPortrait?NAV_HEIGHT:36))-80*PERCEN - 100*PERCEN;
                _compileView.top = _tableView.bottom;
                _compileView.hidden = NO;
            } else {
                //隐藏
                _tableView.height = SCREEN_HEIGHT-(ISIPAD?NAV_HEIGHT:(ISPortrait?NAV_HEIGHT:36))-80*PERCEN;
                _compileView.top = _tableView.bottom;
                _compileView.hidden = YES;
                self.isAllSelcting = NO; //不全选
                [_selectMusicArr removeAllObjects]; //删除所有选中的歌曲
                
                [[NSUserDefaults standardUserDefaults]setObject:@[] forKey:@"SELECT_MUSIC_ALL"];
                [[NSUserDefaults standardUserDefaults]synchronize];

            }
            //返回按钮改变
            if (self.onChangeCompileStatus) {
                self.onChangeCompileStatus(self.isCompiling,self.type);
            }
            [_tableView reloadData];
        }
            break;
        case 2:
        {
            //更多
            //1.批量还原
            if (self.isCompiling) {
                UIButton *bt = (UIButton *)[self.view viewWithTag:1001];
                [self onTapForMusicAction:bt];
            }
            //2,显示
            SharePLayerView *show = [[SharePLayerView alloc]initWithFrame:CGRectZero withType:ShowPlayerType_Moer];//ShowPlayerType_Moer
            show.delegate = self;
            show.orientation = self.orientation;
            [show onShowInWindow];
        }
            break;
            
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 批量操作 取消、删除、收藏
- (void)onSelectItemForCancel:(MBSpaceCollectionCompileView *)view
{
    UIButton *bt = (UIButton *)[self.view viewWithTag:1001];
    [self onTapForMusicAction:bt];
}
//删除 - 删除本地的音频，服务器的不叼他
- (void)onSelectItemForDelete:(MBSpaceCollectionCompileView *)view
{
    if (_selectMusicArr.count > 0) {
        NSMutableArray *newArr = [[NSMutableArray alloc]initWithArray:_selectMusicArr];
        for (NSDictionary *dic in newArr) {
            
            //同步
            FMManageObject *manager = [FMManageObject standerDefault];
            if (self.type == MyCollectionShowType_Music) {
//                NSUInteger index = [_mutAudioArr indexOfObject:dic];
//                [_mutAudioArr removeObject:dic];
//                [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                
                NSArray *arr = [manager SelectTableWithFileID:[dic objectForKey:@"ID"]];
                if (arr.count > 0) {
                    [manager deleteCunstomFileID:[dic objectForKey:@"ID"]];
                }
                NSFileManager *fileManager = [NSFileManager defaultManager];
                if ([fileManager fileExistsAtPath:[MusicCachesDirectory stringByAppendingPathComponent:[dic objectForKey:@"AudioName"]]]) {
                    [fileManager removeItemAtPath:[MusicCachesDirectory stringByAppendingPathComponent:[dic objectForKey:@"AudioName"]] error:NULL];
                }

            }
            else if (self.type == MyCollectionShowType_ParentChildShow) {
                NSArray *arr = [manager SelectTableByLocalParentChildShowWithUserId:[NSString stringWithFormat:@"%@",[dic objectForKey:@"UserID"]] withMusicId:[NSString stringWithFormat:@"%@",[dic objectForKey:@"ID"]]];
                if (arr.count > 0) {
                    NSDictionary *ss = [arr firstObject];
                    [manager deleteByLocalParentChildShowFilID:[ss objectForKey:@"id"]];
                }
                
                NSFileManager *fileManager = [NSFileManager defaultManager];
                if ([fileManager fileExistsAtPath:[MusicCachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"qzx_%@.mp3",[dic objectForKey:@"ShowTitle"]]]]) {
                    [fileManager removeItemAtPath:[MusicCachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"qzx_%@.mp3",[dic objectForKey:@"ShowTitle"]]] error:NULL];
                }
            }
        }
    }
    
    [_selectMusicArr removeAllObjects];
    if (self.type == MyCollectionShowType_Music) {
        if (self.onBackChangeTitle) {
            self.onBackChangeTitle(MyCollectionShowType_Music,_mutAudioArr.count);
        }
    }
    if (_mutAudioArr.count == 0) {
        //已下载歌曲删除完
        UIButton *bt = (UIButton *)[self.view viewWithTag:1001];
        [self onTapForMusicAction:bt];
    }
    
    
    NSArray *musicArr = [[FMManageObject standerDefault]onSelectCustomMusicFileCount];
    if (musicArr.count > 0) {
        [[UserManager standerDefult].downedMusicArr removeAllObjects];
        [[UserManager standerDefult].downedMusicArr addObjectsFromArray:musicArr];
    }
    NSArray *downedMusicArr = [UserManager standerDefult].downedMusicArr;
    [_fileIDArr removeAllObjects];
    NSMutableArray *arr1 = [[NSMutableArray alloc]init];
    NSMutableArray *arr2 = [[NSMutableArray alloc]init];
    for (int i=0; i<downedMusicArr.count; i++) {
        NSDictionary *dic = [downedMusicArr objectAtIndex:i];
        NSString *fileID = [dic objectForKey:@"fileID"];
        [arr1 addObject:fileID];
    }
    NSArray *downedQZXMusicArr = [[FMManageObject standerDefault]onSelectLocalParentChildShowCount];
    for (int i=0; i<downedQZXMusicArr.count; i++) {
        NSDictionary *dic = [downedQZXMusicArr objectAtIndex:i];
        NSString *fileID = [dic objectForKey:@"musicId"];
        if (![arr2 containsObject:fileID]) {
            [arr2 addObject:fileID];
        }
    }
    [_fileIDArr addObject:arr1];
    [_fileIDArr addObject:arr2];
    [_tableView reloadData];
}

//取消收藏 - 服务器数据取消，本地保留
- (void)onSelectItemForNoCollection:(MBSpaceCollectionCompileView *)view
{
    if (_selectMusicArr.count > 0) {
        UserModel *model = [UserManager standerDefult].userModel;
        NSMutableArray  *idArr = [[NSMutableArray alloc]init];
        NSMutableArray *newArr = [[NSMutableArray alloc]initWithArray:_selectMusicArr];
        NSMutableArray *typeArr = [[NSMutableArray alloc]initWithCapacity:newArr.count];
        
        if (self.type == MyCollectionShowType_Music) {
            for (NSDictionary *dic in newArr) {
                [idArr addObject:[dic objectForKey:@"ID"]];
                NSString *proId = @"1";
                [typeArr addObject:proId];
            }
        }
        else if (self.type == MyCollectionShowType_ParentChildShow) {
            if (_isHideAllTableHeaderView) {
                
            } else {
                //取消亲子秀
                for (NSDictionary *dic in newArr) {
                    
                    [idArr addObject:[dic objectForKey:@"ID"]];
                     NSString *proId = @"3";
                    [typeArr addObject:proId];
                }

            }
            
        }
        NSData *date = [NSJSONSerialization dataWithJSONObject:idArr options:NSJSONWritingPrettyPrinted error:nil];
        NSString *idString = [[NSString alloc]initWithData:date encoding:NSUTF8StringEncoding];
        NSData *date2 = [NSJSONSerialization dataWithJSONObject:typeArr options:NSJSONWritingPrettyPrinted error:nil];
        NSString *typeString = [[NSString alloc]initWithData:date2 encoding:NSUTF8StringEncoding];
        
        NSString*url=[NSString stringWithFormat:FAMILYSHOW_COLLECTION_CANCEL_URL_PATH,model.UserID,idString,typeString];
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[HTTPManager standerDefault]AFGetRequest:url view:nil success:^(id json) {
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if ([json[@"ret_code"] integerValue]==0) {
                for (NSDictionary *dic in newArr) {
                    if (self.type == MyCollectionShowType_Music) {
                        NSInteger index = [_mutAudioArr indexOfObject:dic];
                        [_mutAudioArr removeObject:dic];
                        [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                        
                        if ([[UserManager standerDefult].collectionMusicArr containsObject:[dic objectForKey:@"ID"]]) {
                            [[UserManager standerDefult].collectionMusicArr removeObject:[dic objectForKey:@"ID"]];
                        }

                    }
                    else if (self.type == MyCollectionShowType_ParentChildShow) {
                        NSInteger index = [_mutAnchorArr indexOfObject:dic];
                        [_mutAnchorArr removeObject:dic];
                        [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                    }
                }
                
            }
            if (self.type == MyCollectionShowType_Music) {
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Music,_mutAudioArr.count);
                }
            }
            else if (self.type == MyCollectionShowType_ParentChildShow) {
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Anchor,_mutAnchorArr.count);
                }
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];

        
    }
    
    [_selectMusicArr removeAllObjects];
   
    if (_mutAudioArr.count == 0) {
        //已下载歌曲删除完
        UIButton *bt = (UIButton *)[self.view viewWithTag:1001];
        [self onTapForMusicAction:bt];
    }
}

#pragma mark - 勾选一首歌曲
- (void)onSelectItemForGouXuanWithValue:(id)value WithSelect:(BOOL)isSelect WithView:(MBSpaceCollectionMusicCell *)view
{
    //数据保存
    NSLog(@"数据是否需要保存:%d",isSelect);
    if (isSelect) {
        //保存
        [_selectMusicArr addObject:value];
    } else {
        //删除
        if ([_selectMusicArr containsObject:value]) {
            [_selectMusicArr removeObject:value];
        }
    }
    
    //删除、收藏是否可选中
    [_compileView onUpdateDataForDelegateAndCollection:(_selectMusicArr.count > 0 ? YES : NO)];
    
    //如果是全部勾选 就显示全不选；若有一个未勾选 就显示全选
    BOOL isAllSelect = YES;
    if (_selectMusicArr.count != _mutAudioArr.count) {
        isAllSelect = NO;
    }
    if (self.onChangeSuperLeftBt) {
        self.onChangeSuperLeftBt(isAllSelect);
    }
}

//亲子秀勾选
- (void)onSelectPCSItemForGouXuanWithValue:(id)value WithSelect:(BOOL)isSelect WithView:(MBSpaceMyParentChildShowCollectionCell *)view
{
    //数据保存
    NSLog(@"数据是否需要保存:%d",isSelect);
    if (isSelect) {
        //保存
        [_selectMusicArr addObject:value];
    } else {
        //删除
        [_selectMusicArr removeLastObject];
    }
    
    //删除、收藏是否可选中
    [_compileView onUpdateDataForDelegateAndCollection:(_selectMusicArr.count > 0 ? YES : NO)];

    //如果是全部勾选 就显示全不选；若有一个未勾选 就显示全选
    BOOL isAllSelect = YES;
    if (_selectMusicArr.count != _mutAudioArr.count) {
        isAllSelect = NO;
    }
    if (self.onChangeSuperLeftBt) {
        self.onChangeSuperLeftBt(isAllSelect);
    }
}


#pragma mark - 全选
- (void)onSelectAllMusicAction:(BOOL)isAllSelect
{
    self.isAllSelcting = isAllSelect;
    
    //测试
    [_selectMusicArr removeAllObjects];
    if (isAllSelect) {
        if (_type == MyCollectionShowType_Music) {
            [_selectMusicArr addObjectsFromArray:_mutAudioArr];
        }
        else if (_type == MyCollectionShowType_ParentChildShow) {
            [_selectMusicArr addObjectsFromArray:_mutAnchorArr];
        }
    }
    
    //删除、收藏是否可选中
    [_compileView onUpdateDataForDelegateAndCollection:(_selectMusicArr.count > 0 ? YES : NO)];
    
    [_tableView reloadData];
    
}

#pragma mark - 更多操作 添加歌曲、播放、分享、取消收藏、下载
//添加歌曲
- (void)onSelctItemForMoreAddMusic:(SharePLayerView *)view
{
    MBSpaceAddMusicViewController *addMusic = [[MBSpaceAddMusicViewController alloc]init];
    addMusic.type = MBSpaceAddMusicType_Collection;
    [self.navigationController pushViewController:addMusic animated:YES];
}

//每个歌曲更多操作
- (void)onSelectItemForMoewWithValue:(id)value withView:(MBSpaceCollectionMusicCell *)view
{
    
    if (value) {
        _selectCurrentMusicDic = value;
        NSString *idStr = [NSString stringWithFormat:@"%@",[_selectCurrentMusicDic objectForKey:@"ID"]];
        BOOL isDown = NO;
        NSArray *arr1 = [_fileIDArr firstObject];
        if ([arr1 containsObject:idStr]) {
            isDown = YES;
        }
        
        SharePLayerView *show = [[SharePLayerView alloc]initWithFrame:CGRectZero withType:(_isHideAllTableHeaderView ? (isDown ? ShowPlayerType_stroyTabbar:ShowPlayerType_stroyCellMore): (isDown?ShowPlayerType_MusicMoew:ShowPlayerType_CancelCollectionDowned))];
        show.delegate = self;
        show.orientation = self.orientation;
        [show onShowInWindow];
    }
}

//播放
- (void)onSelctItemForMorePlayMusic:(SharePLayerView *)view
{
     if (self.type == MyCollectionShowType_Music) {
         if (_selectCurrentMusicDic.allKeys.count == 0) {
             //第一次
             [[UserManager standerDefult]playMusicWithMusicArray:_mutAudioArr withCurrentIndex:0 withMusicPlayType:_musicPlayType];
         } else if ([_mutAudioArr containsObject:_selectCurrentMusicDic]) {
             int index = (int)[_mutAudioArr indexOfObject:_selectCurrentMusicDic];
             //当前页面播放
             [[UserManager standerDefult]playMusicWithMusicArray:_mutAudioArr withCurrentIndex:index withMusicPlayType:_musicPlayType];
         }
     }
     else if (self.type == MyCollectionShowType_ParentChildShow) {
         if (![_mutAnchorArr containsObject:_selectCurrentMusicDic]) return;
         
         NSInteger index = [_mutAnchorArr indexOfObject:_selectCurrentMusicDic];
         if (_isHideAllTableHeaderView) {
             if (_mutAnchorArr.count > index) {
                 MBSpacePeopelViewController *song = [[MBSpacePeopelViewController alloc]init];
                 song.dateDic = [_mutAnchorArr objectAtIndex:index];
                 song.isFormSearch = YES;
                 [self.navigationController pushViewController:song animated:YES];
             }
         } else {
             if (!self.isCompiling) {
                 //亲子秀
                 
                 UserManager *manager = [UserManager standerDefult];
                 
                 NSString *idStr ;
                 if (manager.audioPlayerType != AudioPLayerType_Qinzix) {
                     //初次进入
                     idStr = @"";
                     manager.audioPlayerType = AudioPLayerType_Qinzix;
                 } else {
                     //2次进入
                     NSInteger selectIndex = manager.selectMusicIndex;
                     NSArray *arr = manager.musicArr;
                     Music *dics = [arr objectAtIndex:selectIndex];
                     idStr = [NSString stringWithFormat:@"%@",dics.ID];
                 }
                 [manager setSelectMusicIndex:index];
                 [manager.musicArr removeAllObjects];
                 [manager.musicArr addObjectsFromArray:[manager onTurnArrayFormQingZiXiuArray:_mutAnchorArr]];
                 manager.selectMusicIndex = index;
                 [manager.qinzixiuArr removeAllObjects];
                 [manager.qinzixiuArr addObjectsFromArray:_mutAnchorArr];
                 
                 MBDetailViewController *childShowVC = [[MBDetailViewController alloc] init];
                 [childShowVC.dataAllArr addObjectsFromArray:_mutAnchorArr];
                 childShowVC.selectMusicID = idStr;
                 [self.navigationController pushViewController:childShowVC animated:YES];
                 
             }
             
         }
     }

}

//分享
- (void)onSelctItemForMoreShareMusic:(SharePLayerView *)view
{
    NSNumber *num = @1;
    NSString *audioName = [_selectCurrentMusicDic objectForKey:@"AudioName"];
    NSString *idStr = [_selectCurrentMusicDic objectForKey:@"ID"];
    NSString *url = [NSString stringWithFormat:SHARE_MUSIC_URL_PATH,idStr];
    if ([_selectCurrentMusicDic.allKeys containsObject:@"ShowTitle"]) {
        num = @3;
        audioName = [_selectCurrentMusicDic objectForKey:@"ShowTitle"];
        url = [NSString stringWithFormat:SHARE_SHOW_URL_PATH,idStr];
    }
    audioName = [[audioName componentsSeparatedByString:@"."]firstObject];
    [shareView setShareVC:self content:[NSString stringWithFormat:@"分享:%@",audioName] image:[UIImage imageNamed:@"logo_dl_29"] url:url];
    [shareView addAudioId:[NSString stringWithFormat:@"%@",idStr] withType:num];
    [shareView show];
}
//取消收藏
- (void)onSelctItemForMoreCancelMusicCollection:(SharePLayerView *)view
{
    if (_selectCurrentMusicDic.allKeys.count > 0) {
        if (![_selectMusicArr containsObject:_selectCurrentMusicDic]) {
            [_selectMusicArr addObject:_selectCurrentMusicDic];
        }
        
        UserModel *model = [UserManager standerDefult].userModel;
        NSMutableArray  *idArr = [[NSMutableArray alloc]init];
        NSMutableArray *newArr = [[NSMutableArray alloc]initWithArray:_selectMusicArr];
        NSMutableArray *typeArr = [[NSMutableArray alloc]initWithCapacity:newArr.count];
        
        if (self.type == MyCollectionShowType_Music) {
            for (NSDictionary *dic in newArr) {
                [idArr addObject:[dic objectForKey:@"ID"]];
                NSString *proId = @"1";
                [typeArr addObject:proId];
            }
        }
        else if (self.type == MyCollectionShowType_ParentChildShow) {
            if (_isHideAllTableHeaderView) {
                
            } else {
                //取消亲子秀
                for (NSDictionary *dic in newArr) {
                    
                    [idArr addObject:[dic objectForKey:@"ID"]];
                    NSString *proId = @"3";
                    [typeArr addObject:proId];
                }
                
            }
            
        }
        NSData *date = [NSJSONSerialization dataWithJSONObject:idArr options:NSJSONWritingPrettyPrinted error:nil];
        NSString *idString = [[NSString alloc]initWithData:date encoding:NSUTF8StringEncoding];
        NSData *date2 = [NSJSONSerialization dataWithJSONObject:typeArr options:NSJSONWritingPrettyPrinted error:nil];
        NSString *typeString = [[NSString alloc]initWithData:date2 encoding:NSUTF8StringEncoding];
        
        NSString*url=[NSString stringWithFormat:FAMILYSHOW_COLLECTION_CANCEL_URL_PATH,model.UserID,idString,typeString];
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[HTTPManager standerDefault]AFGetRequest:url view:nil success:^(id json) {
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if ([json[@"ret_code"] integerValue]==0) {
                for (NSDictionary *dic in newArr) {
                    if (self.type == MyCollectionShowType_Music) {
                        NSInteger index = [_mutAudioArr indexOfObject:dic];
                        [_mutAudioArr removeObject:dic];
                        [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                        
                        if ([[UserManager standerDefult].collectionMusicArr containsObject:[dic objectForKey:@"ID"]]) {
                            [[UserManager standerDefult].collectionMusicArr removeObject:[dic objectForKey:@"ID"]];
                        }
                        
                    }
                    else if (self.type == MyCollectionShowType_ParentChildShow) {
                        NSInteger index = [_mutAnchorArr indexOfObject:dic];
                        [_mutAnchorArr removeObject:dic];
                        [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                    }
                }
                
            }
            if (self.type == MyCollectionShowType_Music) {
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Music,_mutAudioArr.count);
                }
            }
            else if (self.type == MyCollectionShowType_ParentChildShow) {
                if (self.onBackChangeTitle) {
                    self.onBackChangeTitle(MyCollectionShowType_Anchor,_mutAnchorArr.count);
                }
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    }

    [_selectMusicArr removeAllObjects];
}

//下载
- (void)onSelctItemForMoreDownMusic:(SharePLayerView *)view
{
    if (_selectCurrentMusicDic.allKeys.count > 0 && (view.type == ShowPlayerType_stroyCellMore || view.type == ShowPlayerType_CancelCollectionDowned)) {
        [self onLoadMusic:_selectCurrentMusicDic];
        [ErrorMessage showErrorMessage:@"开始下载" inView:self.view];
    }
}

- (void)onLoadMusic:(NSDictionary *)selectCurrentMusicDic
{
    if (self.type == MyCollectionShowType_Music) {
        [[UserManager standerDefult]downLoadMusic:selectCurrentMusicDic withRequestArr:[_fileIDArr objectAtIndex:0]];
    }
    else if (self.type == MyCollectionShowType_ParentChildShow) {
        NSDate *date = [NSDate date];
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString *dateString = [formatter stringFromDate:date];
        
        [[DownManager staredInstance]downloadWithUrl:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,[selectCurrentMusicDic objectForKey:@"FilePath"]]
                                       withMusicName:[NSString stringWithFormat:@"%@.mp3",[selectCurrentMusicDic objectForKey:@"ShowTitle"]]
                                          withUserID:[NSString stringWithFormat:@"%@",[selectCurrentMusicDic objectForKey:@"UserID"]]
                                         withMusicID:[NSString stringWithFormat:@"%@",[selectCurrentMusicDic objectForKey:@"ID"]]
                                         withContent:[NSString stringWithFormat:@"%@",[selectCurrentMusicDic objectForKey:@"Sentiment"]]
                                       withMusicType:[NSString stringWithFormat:@"%@",[[selectCurrentMusicDic objectForKey:@"ShowType"] intValue]==1?@"5":@"6"]
                                          withPicUrl:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,[selectCurrentMusicDic objectForKey:@"CoverPath"]]
                                            withDate:dateString
                                         withUserPic:@""
                                        withUserNick:@""
                                            withSize:[NSString stringWithFormat:@"%@",[selectCurrentMusicDic objectForKey:@"Capacity"]]
                                        withProgress:^(CGFloat progress, NSString *speed, NSString *remainingTime, NSString *writtenSize, NSString *totalSize) {
                                            
                                        } withStats:^(DownMusicState stats) {
                                            
                                        }];
    }

}

#pragma mark - 亲子秀的更多操作
- (void)onSelectPCSItemForMoewWithValue:(id)value withView:(MBSpaceMyParentChildShowCollectionCell *)view
{
    if (value) {
        _selectCurrentMusicDic = value;
        NSString *idStr = [NSString stringWithFormat:@"%@",[_selectCurrentMusicDic objectForKey:@"ID"]];
        BOOL isDown = NO;
        NSArray *arr2 = [_fileIDArr lastObject];
        if ([arr2 containsObject:idStr]) {
            isDown = YES;
        }
        
        SharePLayerView *show = [[SharePLayerView alloc]initWithFrame:CGRectZero withType:(_isHideAllTableHeaderView ? ShowPlayerType_stroyCellMore : (isDown?ShowPlayerType_MusicMoew:ShowPlayerType_CancelCollectionDowned))];
        show.delegate = self;
        show.orientation = self.orientation;
        [show onShowInWindow];
    }
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (self.type) {
        case MyCollectionShowType_Music:
        {
            return _mutAudioArr.count;
        }
            break;
        case MyCollectionShowType_Album:
        {
            return _mutAlbumArr.count;
        }
            break;
        case MyCollectionShowType_ParentChildShow:
        {
            return _mutAnchorArr.count;
        }
            break;
            
        default:
            break;
    }
    return 0	;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (self.type == MyCollectionShowType_Music) {
            //歌曲
            static NSString *cellID = @"Collection_Music_Cell";
            MBSpaceCollectionMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell = [[MBSpaceCollectionMusicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                cell.delegate = self;
            }
            //是否隐藏更多按钮
            cell.isHideMoewBt = NO;
            [cell onCompileCellForLayout:self.isCompiling WithAllSelct:self.isAllSelcting];
            if (_mutAudioArr.count > indexPath.row) {
                NSDictionary *dic = [_mutAudioArr objectAtIndex:indexPath.row];
                cell.musicDic = dic;
                
                BOOL isShowDowned = NO;
                NSArray *arr1 = [_fileIDArr firstObject];
                for (NSString *idStr in arr1) {
                    NSString *string = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ID"]];
                    if ([string isEqualToString:idStr]) {
                        isShowDowned = YES;
                    }
                }
                cell.isShowDowned = isShowDowned;
            }
            
            return cell;
        }
        else if (self.type == MyCollectionShowType_Album) {
            //描述
            static NSString *cellID = @"Collection_Album_Cell";
            MBSpaceMyAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell = [[MBSpaceMyAlbumCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                //增加删除按钮
                UIView *deleteBgView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, 140*PERCEN)];
                deleteBgView.backgroundColor = TINK_BG_COLOR;
                deleteBgView.tag = 103;
                [cell.contentView addSubview:deleteBgView];
                
                UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                deleteBtn.frame = CGRectMake(0, 0, 140*PERCEN, deleteBgView.height);
                [deleteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
                [deleteBgView addSubview:deleteBtn];
            }
            
            UIView *deleteBgView = (UIView *)[cell viewWithTag:103];
             deleteBgView.backgroundColor = TINK_BG_COLOR;
            deleteBgView.left = tableView.width;
            
            cell.orientation = self.orientation;
            if (_mutAlbumArr.count > indexPath.row) {
                cell.dataDic = [_mutAlbumArr objectAtIndex:indexPath.row];
            }
            return cell;
        }
        else if (self.type == MyCollectionShowType_ParentChildShow) {
            if (_isHideAllTableHeaderView) {
                //主播
                static NSString *cellID = @"Collection_ZhuBo_Cell";
                MBSpaceZhuBoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
                if (!cell) {
                    cell = [[MBSpaceZhuBoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                }
                cell.orientation = self.orientation;
                if (_mutAnchorArr.count > indexPath.row) {
                    cell.anchorDic = [_mutAnchorArr objectAtIndex:indexPath.row];
                }
                return cell;
            }
            //亲子秀
            static NSString *cellID = @"Collection_ParentChildShow_Cell";
            MBSpaceMyParentChildShowCollectionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell = [[MBSpaceMyParentChildShowCollectionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.delegate = self;
            }
            [cell onCompileCellForLayout:self.isCompiling WithAllSelct:self.isAllSelcting];
            cell.orientation = self.orientation;
            if (_mutAnchorArr.count > indexPath.row) {
                cell.dataDic = [_mutAnchorArr objectAtIndex:indexPath.row];
            }
            return cell;
        }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == MyCollectionShowType_Music) {
        return 100*PERCEN;
    }
    else if (self.type == MyCollectionShowType_Album) {
        return 140*PERCEN;
    }
    else if (self.type == MyCollectionShowType_ParentChildShow) {
        if (_isHideAllTableHeaderView) {
            return 110*PERCEN;
        }
        return 190*PERCEN;
    }
    return 0;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == MyCollectionShowType_Album) {
        return YES;
    }
    return NO;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete && self.type == MyCollectionShowType_Album) {

        UserModel *model = [UserManager standerDefult].userModel;
        NSDictionary *fileDic = [_mutAlbumArr objectAtIndex:indexPath.row];
        NSString*url=[NSString stringWithFormat:FAMILYSHOW_COLLECTION_CANCEL_URL_PATH,model.UserID,[fileDic objectForKey:@"CollectedID"],@2];
        
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[HTTPManager standerDefault]AFGetRequest:url view:nil success:^(id json) {
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if ([json[@"ret_code"] integerValue]==0) {
                [_mutAlbumArr removeObjectAtIndex:indexPath.row];
                UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
                UIView *deleteBgView = (UIView *)[cell viewWithTag:103];
                deleteBgView.backgroundColor = [UIColor whiteColor];
                [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            }else{
                [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];

    }
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == MyCollectionShowType_Album) {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"*******");
    //编译状态不能点击
    if (self.type == MyCollectionShowType_Music) {
        if (!self.isCompiling) {
            if (![UserManager standerDefult].mainPlayer) {
                //第一次
                [[UserManager standerDefult]playMusicWithMusicArray:_mutAudioArr withCurrentIndex:indexPath.row withMusicPlayType:_musicPlayType];
            }
            else if ([UserManager standerDefult].musicPlayType != _musicPlayType) {
                //第一次
                [[UserManager standerDefult]playMusicWithMusicArray:_mutAudioArr withCurrentIndex:indexPath.row withMusicPlayType:_musicPlayType];
            }
            else if ([UserManager standerDefult].selectMusicIndex != indexPath.row) {
                //当前页面播放
                [[UserManager standerDefult]playMusicWithMusicArray:_mutAudioArr withCurrentIndex:indexPath.row withMusicPlayType:_musicPlayType];
            } else {
                //2次点击进入播放页面
                if ([UserManager standerDefult].musicArr.count > 0) {
                    //歌曲列表没歌曲 无需进入
                    UserManager *manager = [UserManager standerDefult];
                    [manager setSelectMusicIndex:indexPath.row];
                    if (manager.audioPlayerType != AudioPLayerType_YinPin) {
                        [manager setIsPlaying:NO];
                        [manager setAudioPlayerType:AudioPLayerType_YinPin];
                    } else {
                        [manager setIsPlaying:YES];
                    }
//                    if (ISIPAD) {
//                        MBSongDetailForIController*song=[[MBSongDetailForIController alloc]init];
//                        [self.navigationController pushViewController:song animated:YES];
//                    }
                    if (ISIPAD) {
                        MBSongDetailForIpadController*song=[[MBSongDetailForIpadController alloc]init];
                        [self.navigationController pushViewController:song animated:YES];
                        return;
                    }
                    
                    MBSongDetailController *song = [[MBSongDetailController alloc]init];
                    [self.navigationController pushViewController:song animated:YES];
                }
            }

        }
        else {
            //编辑状态就选中勾选
            MBSpaceCollectionMusicCell *cell = (MBSpaceCollectionMusicCell *)[tableView cellForRowAtIndexPath:indexPath];
            if ([cell isKindOfClass:[MBSpaceCollectionMusicCell class]]) {
                [cell onGouXuanToSelectAction:cell.selectBt];
            }
        }
    }
    else if (self.type == MyCollectionShowType_Album) {
        if (_mutAlbumArr.count > indexPath.row) {
            NSDictionary *dic = [_mutAlbumArr objectAtIndex:indexPath.row];
            
            MBSpaceAlbumViewController *song = [[MBSpaceAlbumViewController alloc]init];
            song.titleString = [NSString stringWithFormat:@"%@",[dic objectForKey:@"AlbumName"]];
            song.isFormStroy = _isHideAllTableHeaderView;
            song.dateDic = dic;
            [self.navigationController pushViewController:song animated:YES];
        }
    }
    else if (self.type == MyCollectionShowType_ParentChildShow) {
        if (_isHideAllTableHeaderView) {
            if (_mutAnchorArr.count > indexPath.row) {
                MBSpacePeopelViewController *song = [[MBSpacePeopelViewController alloc]init];
                song.dateDic = [_mutAnchorArr objectAtIndex:indexPath.row];
                song.isFormSearch = YES;
                [self.navigationController pushViewController:song animated:YES];
            }
        } else {
            if (!self.isCompiling) {
                //亲子秀
                
                UserManager *manager = [UserManager standerDefult];
                
                NSString *idStr ;
                if (manager.audioPlayerType != AudioPLayerType_Qinzix) {
                    //初次进入
                    idStr = @"";
                    manager.audioPlayerType = AudioPLayerType_Qinzix;
                } else {
                    //2次进入
                    NSInteger selectIndex = manager.selectMusicIndex;
                    NSArray *arr = manager.musicArr;
                    Music *dics = [arr objectAtIndex:selectIndex];
                    idStr = [NSString stringWithFormat:@"%@",dics.ID];
                }
                //动画效果
                MBSpaceMyParentChildShowCollectionCell *oldCell = (MBSpaceMyParentChildShowCollectionCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:parentSelectAniamtion inSection:0]];
                [oldCell onPlayerQinZinXiuMusicAnimation:NO];
                MBSpaceMyParentChildShowCollectionCell *newCell = (MBSpaceMyParentChildShowCollectionCell *)[_tableView cellForRowAtIndexPath:indexPath];
                [newCell onPlayerQinZinXiuMusicAnimation:YES];
                parentSelectAniamtion = indexPath.row;
                
                [manager setSelectMusicIndex:indexPath.row];
                [manager.musicArr removeAllObjects];
                [manager.musicArr addObjectsFromArray:[manager onTurnArrayFormQingZiXiuArray:_mutAnchorArr]];
                manager.selectMusicIndex = indexPath.row;
                [manager.qinzixiuArr removeAllObjects];
                [manager.qinzixiuArr addObjectsFromArray:_mutAnchorArr];
                
                if (ISIPAD) {
                    MBDetailViewForIpadController*childShowVC=[[MBDetailViewForIpadController alloc]init];
                    childShowVC.dataAllArr = _mutAnchorArr;
                    childShowVC.selectMusicID = idStr;
                    [self.navigationController pushViewController:childShowVC animated:YES];
                    return;

                }
                
                MBDetailViewController *childShowVC = [[MBDetailViewController alloc] init];
               [childShowVC.dataAllArr addObjectsFromArray:_mutAnchorArr];
                childShowVC.selectMusicID = idStr;
                [self.navigationController pushViewController:childShowVC animated:YES];
                
            }
            else {
                //编辑状态就选中勾选
                MBSpaceMyParentChildShowCollectionCell *cell = (MBSpaceMyParentChildShowCollectionCell *)[tableView cellForRowAtIndexPath:indexPath];
                if ([cell isKindOfClass:[MBSpaceMyParentChildShowCollectionCell class]]) {
                    [cell onGouXuanToSelectAction:cell.selectBt];
                }
            }
        }
    }
   
}

@end
